package com.wealth.scsj.b_app.model;




import com.wealth.scsj.b_app.base.EvaluateStatisBase;
import com.wealth.scsj.b_app.base.UserEvaluateBase;
import com.wealth.scsj.b_app.bean.EvaluationStatisticsScoreBean;
import com.wealth.scsj.b_app.bean.GetEvaluationNumBean;
import com.wealth.scsj.b_app.bean.UserEvaluateListBean;

import dkmvp.net.ResponseCallback;
import dkmvp.net.ResponseHandler;
import dkmvp.net.RetryWithDelay;
import okhttp3.RequestBody;
import rx.Observable;
import rx.Subscription;
import rx.android.schedulers.AndroidSchedulers;
import rx.functions.Action1;
import rx.schedulers.Schedulers;

/**
 * 修改登录密码Model
 */

public class EvaluateStatisModel extends BaseModel implements EvaluateStatisBase.IModel {


    @Override
    public Subscription getData(RequestBody requestBody, final ResponseCallback<EvaluationStatisticsScoreBean> callback) {
        Observable<EvaluationStatisticsScoreBean> observable = service.getEvaluationStatisticsScore(requestBody);
        Subscription sub = observable.subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .retryWhen(new RetryWithDelay(3, 3000))//总共重试3次，重试间隔3秒
                .subscribe(new Action1<EvaluationStatisticsScoreBean>() {
                    @Override
                    public void call(EvaluationStatisticsScoreBean result) {
                        callback.onSuccess(result);
                    }
                }, new Action1<Throwable>() {
                    @Override
                    public void call(Throwable throwable) {
                        callback.onFaild(ResponseHandler.getErrorMsg(throwable));
                    }
                });
        return  sub;
    }

    /**
     * 获取评价个数
     * @param requestBody
     * @param callback
     * @return
     */
    @Override
    public Subscription getEvaluationNumData(RequestBody requestBody, final ResponseCallback<GetEvaluationNumBean> callback) {
        Observable<GetEvaluationNumBean> observable = service.getEvaluationNum(requestBody);
        Subscription sub = observable.subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .retryWhen(new RetryWithDelay(3, 3000))//总共重试3次，重试间隔3秒
                .subscribe(new Action1<GetEvaluationNumBean>() {
                    @Override
                    public void call(GetEvaluationNumBean result) {
                        callback.onSuccess(result);
                    }
                }, new Action1<Throwable>() {
                    @Override
                    public void call(Throwable throwable) {
                        callback.onFaild(ResponseHandler.getErrorMsg(throwable));
                    }
                });
        return  sub;
    }


}
